const { exec } = require('child_process');

const { arch, platform } = process;

// Run patch-package with timeout
const patchPackage = exec('npx patch-package @tencentcloud/roomkit-electron-vue3', {
  timeout: 300000 // 5 minutes timeout
});

patchPackage.stdout.on('data', (data) => {
  console.log(`patch-package: ${data}`);
});

patchPackage.stderr.on('data', (data) => {
  console.error(`patch-package error: ${data}`);
});

patchPackage.on('close', (code) => {
  if (code !== 0) {
    console.error(`patch-package process exited with code ${code}`);
    process.exit(1);
  }
  console.log('patch-package completed successfully');
});

if (platform === 'darwin') {
  console.log('postinstall:', process.cwd());
  exec(`rsync -a ./node_modules/trtc-electron-sdk/build/mac-framework/${arch}/ ./node_modules/electron/dist/Electron.app/Contents/Frameworks`);
}
